* robustness_informal_edom_bite_industry_ccity.do	JEP	03/11/15
* Does regressions that are in the term paper, for informal workers: RIF10
* Exclude domestic workers
* Monthly wage
* Extended bite

*************************** Change log ********************************** 

/*
	
*/	

clear 
version 13.1

* Project info
cap project, doinfo
if _rc==198 {
	if c(os)=="Unix" loc master "/home/jperez/AA_Minimum_Wage" 
 else if c(username)=="J16339" loc master "B:\Col_Minimum_Wage" 
 	else loc master "C:/Users/jorpp/Dropbox (Brown)/Col_Minimum_Wage"
 loc pr = 0
}
else {
	local master "`r(pdir)'"
	local doname "`r(dofile)'"  
 loc pr = 1
	* Project calls
	project, uses("`master'/Data/Source/ocupados_mw.dta")
	* Call programs
	project, relies_on("`master'/Code/Est/sample_choice.do")
	project, relies_on("`master'/Code/Est/build_mw_measures.do")
	project, relies_on("`master'/Code/Est/build_treatment.do")
	project, relies_on("`master'/Code/Est/export_rif.do")
	project, relies_on("`master'/Code/Est/confirmedrun.do")
	project, relies_on("`master'/Code/Est/graph_rif.do")
}
*/


* Call necessary programs. I do not call using project to carry the programs around. I do not put these in the ado/personal folder because they are specific to the project. They are not ado files.
do "`master'/Code/Est/sample_choice.do"
do "`master'/Code/Est/build_mw_measures.do"
do "`master'/Code/Est/build_treatment.do"
do "`master'/Code/Est/export_rif.do"
do "`master'/Code/Est/confirmedrun.do"
do "`master'/Code/Est/graph_rif.do"


use "`master'/Data/Source/ocupados_mw.dta", clear

* Choose quantiles
glo qtiles "5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90"
* Number of bootstraps
glo boot=200

* RIF 4 - Tables numbered 4 in term paper

* Choose sample
mysample rif10sample , hmin(30) hmax(50) sex(0) edadm(65) wage(salario) informal exind(13,29,42)
tab rif10sample
tab tipo_trabajador if rif10sample
tab year if rif10sample
tab horas_semana if rif10sample 
tab sex if rif10sample
tab afiliado_salud if rif10sample
* Build mw measures
mw_measures rif10sample , stub(rif10) time("tq(1998q3)")
* Build treatment
mytreatment, posts("tq(1998q4)") mw(bite_rif10_ind) wage(salario_mensual_real)

* RIF regressions

* Create estimation results folder if it doesn't already exist
cap mkdir "`master'/Ster/rif10_new_indcc"

* For these I'm going to assume the clusters are the city - industry pairs. This assumes that there is not correlation within city across industries, only within those pairs. Could also run with the standard clustering by city, but that would mean that I'm not really increasing the sample size by running within industry.

* The number of clusters is large enough that I don't need the full CGM framework, can run just with cluster
egen city_ind=group(ccode cactividad_empresa)


foreach x in $qtiles {

	di " Percentile `x'"
	loc fw: word 1 of $qtiles
	loc count: word count $qtiles
	di `count'
	loc lw: word `count' of $qtiles
	if `x'==`lw' & `pr'!=0 loc reg="register"
	else loc reg ""
	if `x'==`fw' loc r="replace"
	else loc r="append"
	/*
	* Panel A. Employment
	confirmedrun, `reg' controls() name(`master'/Ster/rif10_new_ebite_indcc/reg_emp_tq(1998q4)_ebite_salario_mensual_real_50_edom_indcc) rif(rif10A) p(`x') r(`r') sample(rif10sample) fe(i.ccode#i.cactividad_empresa i.time) cluster(ccode)
	* cgmrif2 lw treat i.ccode i.time emp if rif10sample , hyp(0) boot($boot) cluster(ccode) x(treat) i(ccode) t(time) q(`x') rif(rif10A`x')
	* exportrif, name(`master'/Ster/rif10_new_ebite_indcc/reg_emp_tq(1998q4)_ebite_salario_mensual_real_50_edom) p(`x') r(`r')
	*/
	* Panel B. Employment and Bartik Price Variable
	* confirmedrun, `reg' controls(bartikp1_ex) name(`master'/Ster/rif10_new_indcc/reg_emp_bp_tq(1998q4)_bite_salario_mensual_real_50_edom_indcc) rif(rif10B) p(`x') r(`r') sample(rif10sample) fe(i.ccode#i.cactividad_empresa i.time) cluster(ccode) rerun
	* Panel C. Employment and Bartik Quantity Variable
	*confirmedrun, `reg' controls(bartikq_ex) name(`master'/Ster/rif10_new_ebite_indcc/reg_emp_bq_tq(1998q4)_ebite_salario_mensual_real_50_edom_indcc) rif(rif10C) p(`x') r(`r') sample(rif10sample) fe(i.ccode#i.cactividad_empresa i.time) cluster(ccode)
	/*
	* Panel D. Employment and City Trends
	confirmedrun, `reg' controls(i.ccode#c.trend) name(`master'/Ster/rif10_new_ebite_indcc/reg_sst_emp_tq(1998q4)_ebite_salario_mensual_real_50_edom_indcc) rif(rif10D) p(`x') r(`r') sample(rif10sample) fe(i.ccode#i.cactividad_empresa i.time) cluster(ccode)
	*/
	* Panel E. Employment, Bartik Price Variable and City Trends
	*confirmedrun, `reg' controls(i.ccode#c.trend bartikp1) name(`master'/Ster/rif10_new_ebite_indcc/reg_sst_emp_bp_tq(1998q4)_ebite_salario_mensual_real_50_edom_indcc) rif(rif10E) p(`x') r(`r')  fe(i.ccode#i.cactividad_empresa i.time) cluster(ccode)sample(rif10sample) 
	* Panel F. Employment, Bartik Quantity Variable and City Trends
	*confirmedrun, `reg' controls(i.ccode#c.trend bartikq) name(`master'/Ster/rif10_new_ebite_indcc/reg_sst_emp_bq_tq(1998q4)_ebite_salario_mensual_real_50_edom_indcc) rif(rif10F) p(`x') r(`r') fe(i.ccode#i.cactividad_empresa i.time) cluster(ccode)sample(rif10sample) 
	* Panel G. Employment, Bartik Quantity Variable and City - Industry fe, city fe and interactions
	*confirmedrun, `reg' controls(bartikp1_ex) name(`master'/Ster/rif10_new_ebite_indcc/reg_emp_bp_ixc_tq(1998q4)_ebite_salario_mensual_real_50_edom_indcc) rif(rif10G) p(`x') r(`r') sample(rif10sample) fe(i.ccode##i.cactividad_empresa i.time) cluster(ccode)
	* Panel H. Employment, Bartik Quantity Variable and City - Industry fe, city fe and interactions
	*confirmedrun, `reg' controls(bartikq_ex) name(`master'/Ster/rif10_new_ebite_indcc/reg_emp_bq_ixc_tq(1998q4)_ebite_salario_mensual_real_50_edom_indcc) rif(rif10H) p(`x') r(`r') sample(rif10sample) fe(i.ccode##i.cactividad_empresa i.time) cluster(ccode)
	/*
	
	* Panel I - Employment, Bartik Price Variable - Industry fe, city fe and interactions - City Industry trends
	confirmedrun, `reg' controls(bartikp1_ex) name(`master'/Ster/rif10_new_ebite_indcc/reg_ct_emp_bp_ixc_tq(1998q4)_ebite_salario_mensual_real_50_edom_indcc) rif(rif10I) p(`x') r(`r') sample(rif10sample) fe(i.ccode##i.cactividad_empresa i.ccode#i.cactividad_empresa#c.trend i.time) cluster(ccode)	
	* Panel J. Employment, Bartik Quantity Variable and City - Industry fe, city fe and interactions
	confirmedrun, `reg' controls(bartikq_ex) name(`master'/Ster/rif10_new_ebite_indcc/reg_ct_emp_bq_ixc_tq(1998q4)_ebite_salario_mensual_real_50_edom_indcc) rif(rif10J) p(`x') r(`r') sample(rif10sample) fe(i.ccode##i.cactividad_empresa i.ccode#i.cactividad_empresa#c.trend i.time) cluster(ccode)
	*/
}

* Graph results and export

clear

cap program drop mex
program define mex
	cap mkdir "`2'/Doc/ster_figures/rif10_new_indcc"
	cap mkdir "`2'/Doc/ster_figures/rif10_new_indcc/1998q4"
	graph export "`2'/Doc/ster_figures/rif10_new_indcc/1998q4/`1'.eps", replace
	! epstopdf "`2'/Doc/ster_figures/rif10_new_indcc/1998q4/`1'.eps"
	erase "`2'/Doc/ster_figures/rif10_new_indcc/1998q4/`1'.eps"
	* project, creates("`master'/Doc/descriptive_figures/density/`1'.pdf")
end	

* foreach spec in reg_emp_bp reg_emp_bq reg_sst_emp_bp reg_sst_emp_bq reg_emp_bq_ixc reg_emp_bp_ixc {
foreach spec in reg_emp_bp {
	graph drop _all
	graphrif, master("`master'") ster(Ster) folder(rif10_new_indcc) qtiles($qtiles) spec(`spec') time(tq(1998q4)) rareaopts(bcolor(gs13))twowayopts(title(Informal sector - By city industry - `spec' ) xtitle(Percentile) ytitle(Coef))
	mex `spec' `master'
}



